package com.homedo.microservice.wechat.personal.secretary.entity;


import io.github.biezhi.wechat.api.model.Account;

import java.util.ArrayList;
import java.util.List;

public class CheckFriendRelationshipBiz extends Biz {

    public CheckFriendRelationshipBiz() {
        this("查看哪些好友删除了自己", BizConstants.CHECK_FRIEND_RELATIONSHIP, 1, null);
    }

    public CheckFriendRelationshipBiz(String name, String code, float sort, PersonalBotBiz botBiz) {
        super(name, code, sort, botBiz);
    }

    //处理检查好友关系的任务
    public synchronized void dealBiz() {

        List<Account> releasedFriends = this.getReleasedFriends();

        if (releasedFriends == null || releasedFriends.size() == 0) {
            getBotBiz().getBot().sendMsgToFileHelper("所有好友关系都正常");
            return;
        }

        StringBuilder msg = new StringBuilder("以下好友已经解除了与你的好友关系:\n");

        for (int i = 0; i < releasedFriends.size(); i++) {
            Account account = releasedFriends.get(i);
            String name = account.getRemarkName() == null ? account.getNickName() : account.getRemarkName();
            msg.append(i + 1).append(" ").append(name).append("\n");
        }

        msg.append("执行清理，请回复20000");

        getBotBiz().getBot().sendMsgToFileHelper(msg.toString());

    }

    public List<Account> getReleasedFriends() {
        List<Account> accounts = new ArrayList<>();

        //TODO 检查哪些已不是好友关系
        for (int i = 0; i < 10; i++) {
            Account account = new Account();
            account.setRemarkName("张三" + i);

            accounts.add(account);
        }

        return accounts;
    }
}
